﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MS.Data.API.Write.Applicant.Command;
using MS.Data.Domain;
using MS.Data.ErrorCode;

namespace MS.Data.API.Write.Controllers
{
    /// <summary>
    /// API控制器-写
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MangController : ControllerBase
    {
        /// <summary>
        /// 中介者
        /// </summary>
        IMediator mediator;
        /// <summary>
        /// 日志
        /// </summary>
        ILogger<MangController> logger;
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="mediator">中介者</param>
        /// <param name="logger">日志</param>
        public MangController(IMediator mediator, ILogger<MangController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="add">请求</param>
        /// <returns>返回结果</returns>
        [HttpPost]
        public async Task<APIResult<int>> AddPermission(AddPermissionCommand add)
        {
            return await mediator.Send(add);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="del">请求</param>
        /// <returns>返回结果</returns>
        [HttpDelete]
        public async Task<APIResult<int>> Del([FromQuery] DelCommand del)
        {
            return await mediator.Send(del);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="updatet"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<Permission>>> Updatet([FromQuery] UpdateCommand updatet)
        {
            return mediator.Send(updatet);
        }
        [HttpPut]
        public async Task<APIResult<int>> Xiu(XiuCommand request)
        {
            return await mediator.Send(request);
        }
    }
}
